﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InductBase.Extra
{
    struct Color
    {
        private double a, r, g, b;

        public int A { get { return (int)a; } set { a = Math.Max(0, Math.Min(value, 255)); } }
        public int R { get { return (int)a; } set { a = Math.Max(0, Math.Min(value, 255)); } }
        public int G { get { return (int)a; } set { a = Math.Max(0, Math.Min(value, 255)); } }
        public int B { get { return (int)a; } set { a = Math.Max(0, Math.Min(value, 255)); } }

        public Color(double a, double r, double g, double b)
        {
            this.a = Math.Max(0, Math.Min(a, 255));
            this.r = Math.Max(0, Math.Min(r, 255));
            this.g = Math.Max(0, Math.Min(g, 255));
            this.b = Math.Max(0, Math.Min(b, 255));
        }

        public static Color operator +(Color a, Color b)
        {
            return new Color(a.a + b.a, a.r + a.r, a.g + b.g, a.b + b.b);
        }

        public static Color operator -(Color a, Color b)
        {
            return new Color(
                a.a - b.a,
                a.r - a.r,
                a.g - b.g,
                a.b - b.b);
        }

        public static Color operator *(Color a, Color b)
        {
            return new Color(
               a.a * b.a,
               a.r * a.r,
               a.g * b.g,
               a.b * b.b);
        }

        public static Color operator /(Color a, Color b)
        {
            return new Color(
               a.a / b.a,
               a.r / a.r,
               a.g / b.g,
               a.b / b.b);
        }

        public static Color operator *(Color a, double b)
        {
            return new Color(
               a.a * b,
               a.r * b,
               a.g * b,
               a.b * b);
        }

        public static Color operator *(double b, Color a)
        {
            return new Color(
               a.a * b,
               a.r * b,
               a.g * b,
               a.b * b);
        }

        public static Color operator /(Color a, double b)
        {
            return new Color(
               a.a / b,
               a.r / b,
               a.g / b,
               a.b / b);
        }

        public static bool operator ==(Color a, Color b)
        {
            return
                a.a == b.a &&
                a.r == b.r &&
                a.g == b.g &&
                a.b == b.b;
        }

        public static bool operator !=(Color a, Color b)
        {
            return !
                (a.a == b.a &&
                a.r == b.r &&
                a.g == b.g &&
                a.b == b.b);
        }

    }
}
